package io.kiki.sba.registry.server.metadata.slot.util.selector;

import io.kiki.sba.registry.server.metadata.slot.util.builder.SlotsBuilder;
import io.kiki.sba.registry.server.metadata.slot.util.comparator.Comparators;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

abstract class AbstractDataServerSelector extends AbstractSlotsBuilderAwareSelector<String> {

    public AbstractDataServerSelector(SlotsBuilder slotsBuilder) {
        super(slotsBuilder);
    }

    @Override
    public String select(Collection<String> dataStoreNodeIdList) {
        List<String> list = new ArrayList<>(dataStoreNodeIdList);
        list.sort(getDataStoreNodeComparator());
        return list.isEmpty() ? null : list.get(0);
    }

    protected abstract Comparators.AbstractDataStoreNodeComparator getDataStoreNodeComparator();
}
